<template>
	<view>
		<view class="uni-header">
			<view class="uni-group">
				<view class="uni-title">订单管理</view>
				<view class="uni-sub-title">/订单列表</view>
			</view>
			<view class="uni-group">
				<view class="select" style="width:220px;" >
					<uni-datetime-picker type="datetimerange" 
						:clear-icon="false" v-model="single" @change="datetimePicker" 
						return-type="timestamp"
						:start="Date.now() - ((1000*60 * 60)*24*30 )"
						:end="Date.now()"
						rangeSeparator="至"
					/>
				</view>
				<view class="select">
					<uni-data-select v-model="selectTimeVal" :clear="false" :localdata="range" @change="changeDateSelect"></uni-data-select>
				</view>
				<view class="select" style="width:200px" >
					<uni-data-picker placeholder="请选择所在地区" popup-title="请选择所在地区" :localdata="dataTree" @change="onchange" :clear-icon="false">
					</uni-data-picker>
				</view>
				<input class="uni-search" type="text" v-model="query" @confirm="search" placeholder="请输入订单号或手机号" />
				<button class="uni-button" type="default" size="mini" @click="search">搜索</button>

			</view>
		</view>
		<!-- <button type="primary" @click="onclick" >火箭发射</button> -->

		<view class="uni-container">
			<unicloud-db ref="udb" :collection="collectionList"
				field="provider,shop_id,orders_source,service_text,pay_status,refund,group_buying_price,refund_total_price,status,pay_type,service_type,service_time,reality_service_time,serial_number,cancel_order,rider,type,reminder,order_no,delivery_price,timeOut,deduct_delivery_price,total_price,pack_price,preferential,user_id,nickname,notes,address,client_ip,openid,description,err_msg,total_fee,refund_fee,refund_count,refund_list,is_receive_order,provider_appid,appid,user_order_success,custom,original_data,create_date,pay_date,notify_date,cancel_date,is_comment,stat_data"
				:where="orderWhere" page-data="replace" :orderby="orderby" :getcount="true" :page-size="options.pageSize"
				:page-current="options.pageCurrent" v-slot:default="{data,pagination,loading,error,options}"
				:options="options" loadtime="manual" @load="onqueryload"
			>
				<uni-table ref="table" :loading="loading" :emptyText="data.length || '暂无更多数据'" stripe type="selection"
					@selection-change="selectionChange">
					<uni-tr>
						<uni-th align="center">
							#
						</uni-th>
						<uni-th align="center"  >
							商铺名称
						</uni-th>
						<uni-th align="center" sortable @sort-change="sortChange($event, 'rider')">
							骑手信息
						</uni-th>
						<uni-th align="center">
							收货人
						</uni-th>
						<uni-th align="center" filter-type="search" @filter-change="filterChange($event, 'order_no')" sortable @sort-change="sortChange($event, 'order_no')">
							订单号
						</uni-th>
						<uni-th align="center" filter-type="select" :filter-data="optionsStatus"
							@filter-change="onFilter( $event ,'status')">
							订单状态
						</uni-th>
						<uni-th align="center">
							总金额
						</uni-th>
						
						<uni-th align="center">
							下单平台
						</uni-th>
						<uni-th align="center">配送费</uni-th>
						<uni-th align="center">打包费</uni-th>
						<uni-th align="center">
							支付时间
						</uni-th>
						
						<uni-th width="420" align="center">操作</uni-th>
					</uni-tr>
					<uni-tr v-for="(item,index) in data" :key="index">
						<!-- 编号 -->
						<uni-td align="center" style="font-weight:bold">
								<text>
									{{item.serial_number}}
								</text>
						</uni-td>
						<!-- 店铺 -->
						<uni-td align="left">
							<view v-for="items in item.shop_id" class="titleApp" >
								<navigator :url="`/pages/shop/shop/shop-info?_uid=${item.shop_id[0]._id}`">
									<text class="titleApp ">
										<tooltip :isContainer="true" containerWidth="330rpx"  :text-content="items.title" :text-tip="'备注:'+item.notes" ></tooltip>
									</text>									  
								</navigator>
							</view>
						</uni-td>
						<!-- 骑手 -->
						<uni-td align="center">
							<view>
								<view v-if="item.rider" style="display: flex;justify-content: center;">
									<navigator v-if="isPower(['admin','administrators','region'])" :url="`/pages/rider/rider_users/detail?_uid=${item.rider.user_id}`">
										<text> {{item.rider.nickname}} </text>
									</navigator>
									<text v-else > {{item.rider.nickname}} </text>
									-
									<text class="telApp">
										{{ mobileReconfiguration(item.rider.mobile)}}
									</text>
								</view>
								<text v-else>
									暂未分配
								</text>
							</view>
						</uni-td>
						<!-- 用户 -->
						<uni-td align="center">
							<view v-if="IsAdddress(item.address)" style="display: flex;justify-content: center;">
								<navigator  :url="`/pages/system/user/detail?id=${item.address.user_id}`">
									<text>{{item.address?item.address.name:''}} </text> - 
								</navigator>
								<text class="container " >
									{{item.address?item.address.title :''}} - 
								</text>
								<text class="telApp" >
										<!-- {{ ( item.address?mobileReconfiguration(item.address.phone):'暂无')  }} -->
										<heightText :textContetn="( item.address?mobileReconfiguration(item.address.phone):'暂无')" :textTitle="query" ></heightText>
								</text>
							</view>

						</uni-td>
						<!-- 单号 -->
						<uni-td align="center">
							<view style="cursor:pointer;display: flex;" class="" @click="navigateTo('/pages/order/uni-pay-orders/detail?id='+item.order_no, false)" >
								<heightText :textContetn="item.order_no" :text-title="query"  ></heightText>
								&nbsp;<text class="copy" @click.stop="copyOrderNo(item.order_no)" > 复制</text>
							</view>
						</uni-td>
						<!-- 状态 -->
						<uni-td align="center" >
							<text :style="`color:${ onStatus(item.status.value) }`" >
								<text  >
									<text v-if="item.refund &&  item.status.value!=9" >
										{{item.status.text}}
									</text>
									<text  v-else-if="item.status.value<=5"  >
										{{item.status.text}}
									</text>
									<text v-else-if="!item.refund" >
										{{item.status.text}}
									</text>
								</text>
								<text v-if="item.refund && item.status.value!=5" style="color:#999" >
									&nbsp; {{item.refund?item.refund.text: ''}} 
								</text>
							</text>
							<text>
								- {{item.type==2?'到店就餐':item.service_text=='预约时间送达'?'按预约时间送达':'外卖配送'}}
							</text>
						</uni-td>
						<!-- 金额 -->
						<uni-td align="center">
							<text class="fontColorApp">
								￥{{item.total_fee/100}}
							</text>
						</uni-td>
						
						<!-- 下单来源 -->
						<uni-td align="center">
							{{item.orders_source?item.orders_source : '暂无信息'}}
						</uni-td>
						<!-- 收取客户的配送费 -->
						<uni-td align="center">
							<text class="fontColorApp">
								￥{{item.delivery_price/100}}
							</text>
						</uni-td>
						<!-- 打包费 -->
						<uni-td align="center">
							<text class="fontColorApp">
								￥{{item.pack_price/100}}
							</text>
						</uni-td>
						<!-- 支付时间 -->
						<uni-td align="center">
							<uni-dateformat :date="item.pay_date" format="MM月dd日 hh:mm" ></uni-dateformat>
						</uni-td>
						<uni-td align="center">
							<view class="uni-group">
								<button @click="onOpention(item.shop_id,1)" class="uni-button" size="mini" type="primary">
									语音提醒
								</button>
								<button @click="onOpention(item,3)" class="uni-button" size="mini" type="primary">
									更换骑手
								</button>
								<button :disabled="!isPower(['admin','region'])" @click="onOpention(item,4)" class="uni-button"
									size="mini" type="warn">
									修改状态
								</button>
								<button size="mini" type="warn" @click="onOpention(item,2)" :disabled="!isPower(['admin'])" v-if="!item.refund" >
									取消订单
								</button>
								<button size="mini" v-else type="warn" @click="onOpention(item,2)" :disabled="!isPower(['admin'])">
									同意退款
								</button>
							</view>
						</uni-td>

					</uni-tr>
				</uni-table>
				<view class="uni-pagination-box">
					<uni-pagination show-icon :page-size="pagination.size" v-model="pagination.current"
						:total="pagination.count" @change="onPageChanged" />
				</view>
			</unicloud-db>
		</view>
		<!-- 修改状态 -->
		<uni-popup ref="showUpdateStatus" type="center" backgroundColor="#fff">
			<view class="popup">
				<view class="title">
					修改状态
				</view>
				<view class="body">
					<view>
						<text>店铺：</text>
						<text class="titleApp">
							{{temp_uid.shop_id[0].title}}
						</text>
					</view>
					<view>
						<text>订单号：</text>
						<text class="">
							{{temp_uid.order_no}}
						</text>
					</view>
					<view class="maxbox" style="min-height:200px;">
						<uni-data-select v-model="selectStatus" :localdata="rangeStatus"></uni-data-select>
					</view>
					<view style="margin:20px 0;">
						<button @click="updateStatus()" class="uni-button" size="mini" type="primary">
							确认修改
						</button>
						<button @click="this.$refs.showUpdateStatus.close()" class="uni-button" size="mini" type=" ">
							取消
						</button>
					</view>
				</view>
			</view>
		</uni-popup>
		<!-- 更换骑手 -->
		<uni-popup ref="showUpdateRider" type="center" style="border-radius:20px;" backgroundColor="#fff">
			<view class="popup">
				<view class="title">
					更换骑手
				</view>
				<view class="body">
					<view>
						<text>店铺：</text>
						<text class="titleApp">
							{{temp_uid.shop_id[0].title}}
						</text>
					</view>
					<view>
						<text>
							当前骑手：
						</text>
						<text class="titleApp">
							{{temp_uid.rider?temp_uid.rider.nickname:'暂无骑手'}}
						</text>
					</view>
					<view class="titleApp" style="font-size:14px">
						更换为:
						<text>
							{{ rangeRider[selectRider].text }}
						</text>
					</view>
					<view class="maxbox">
						<view class="grid">
							<view class="item_box" v-for="(item,index) in rangeRider" @click="handleItemClick(item,index)"
								:class="index===selectRider?'item_boxTow':''">
								<view>
									<image class="image" :src="item.avatar+ '?x-oss-process=image/resize,m_fixed,h_200,w_200'"
										mode="widthFix"></image>
								</view>
								<view class="label">
									{{item.text}}
								</view>
								<view class="label">
									{{item.order_number}} 单
								</view>
							</view>
						</view>
					</view>
					<view style="margin:20px 0;">
						<button @click="updateRider()" class="uni-button" size="mini" type="primary">
							确认更换
						</button>
						<button @click="this.$refs.showUpdateRider.close()" class="uni-button" size="mini" type=" ">
							取消
						</button>
					</view>
				</view>
			</view>
		</uni-popup>
		<!-- 语音提醒 -->
		<uni-popup ref="showStatus" type="center" style="border-radius:20px;" backgroundColor="#fff">
			<view class="popup">
				<view class="titleApp">
					选择语音催餐
				</view>
				<view class="body">
					<view style="margin:20rpx 0">
						Tel: <text style="color:#ff6600">{{mobileReconfiguration(temp_uid)}}</text>
					</view>
					<view style="margin:100rpx 0">
						"语音催接单"指的是通过语音方式来催促商家或者服务提供方尽快接受订单。
					</view>
					<button @click="eventVoice" class="uni-button" size="mini" type="primary">
						催 接 单
					</button>
				</view>
			</view>
		</uni-popup>
		<!-- 取消订单提醒 -->
		<uni-popup ref="showOrderOut" type="center" style="border-radius:20px;" backgroundColor="#fff">
			<view class="popup">
				<view class="titleApp">
					取消当前订单
				</view>
				<view class="body">
					<view style="margin:20rpx 0">
						<view style="margin:20rpx 0;color:#565656">
							确认取消订单后，金额将会如数退还给用户。
						</view>
						<view class="titleApp">
							须知！
						</view>
						<view class="labelApp">
							取消订单:只能取消未完成订单和未取消订单，取消后包括商家账单/金额也会更改，订单金额也会如数奉还给用户。在后台取消订单不会扣除订单的20%计算到商家头上。
							<view style="font-weight:bold;color:#ff3300;margin:10px 0">
								请与上级领导落实准确，切勿私自取消订单，否则后果自负!
							</view>
						</view>
					</view>
					<button @click="toRefund"  class="uni-button" size="mini" type="warn">
						取消订单
					</button>
					<button @click="this.$refs.showOrderOut.close()" class="uni-button" size="mini" type="">
						取消
					</button>
				</view>
			</view>
		</uni-popup>
	</view>
	<uni-pay ref="pay" :adpid="adpid" height="70vh" return-url="/pages/index/index" logo="/static/logo.png"></uni-pay>

</template>

<script>
	import Util from "@/js_sdk/validator/util.js"
	import {filterToWhere} from '@/js_sdk/validator/orders.js';
	import error from "../../../store/modules/error";
	import {updateRider,updateStatus} from "./order.js"
	// 区域管理
	// import {getArea} from "@/pages/shop/shop/shop-info.js"
	import { areaPower ,getArea } from "@/js_sdk/manage-area/manage.js";
	const PUSH = uniCloud.importObject("push", {customUI: true})
	const order = uniCloud.importObject("order", {customUI: true})
	const db = uniCloud.database()
	const global = uniCloud.importObject("global", {customUI: true})
	// 表查询配置
	const dbOrderBy = '' // 排序字段
	const dbSearchFields = [] // 模糊搜索字段，支持模糊搜索的字段列表。联表查询格式: 主表字段名.副表字段名，例如用户表关联角色表 role.role_name
	// 分页配置
	const pageSize = 20
	const pageCurrent = 1
	const orderByMapping = {
		"ascending": "asc",
		"descending": "desc"
	}
	let where_uid = null;
	
	export default {
		data() {
			return {
				startTime: 0,
				endTime: 0,
				//a 日期下拉框
				selectTimeVal: 0,
				range: [
					{value: 0,text: "今日订单"},
					{value: 1,text: "昨日订单"},
					{value: 2,text: "一周内订单"},
					{value: 3,text: "一月内订单"}
				],
				rangeStatus: [
					{value: 0,text: "待支付"},
					{value: 1,text: "待接单"},
					{value: 2,text: "已接单"},
					{value: 3,text: "骑手已到店"},
					{value: 4,text: "骑手已取餐"},
					{value: 5,text: "订单完成"},
					{value: 9,text: "管理员取消"},
				],
				// 更换骑手
				tempRider: {},
				selectRider: 0,
				rangeRider: [],
				selectStatus: 0,
				optionsStatus: [{value: 0,text: "有效订单"},
					{value: 1,text: "全部订单"},
					{value: 2,text: "正在进行中"},
					{value: 3,text: "已完成订单"},
					{value: 4,text: "已取消订单"}
				],
				optionType: [{value: 0,text: "外卖配送"},
					{value: 1,text: "预约送达"},
					{value: 2,text: "到店就餐"}
				],
				// 级联菜单
				dataTree:[],
				temp_uid: null,
				collectionList: [
					db.collection('orders').orderBy("create_date.time_stamp desc").getTemp(),
					db.collection('shop').field("_id,title,tel,area_all").getTemp({
						getOne: true
					})
				],
				query: '',
				orderWhere: {
					"create_date.time_stamp": db.command.gt(Util.getDayTimestamps(0).startTime).and(db.command.lt(Util.getDayTimestamps(0).endTime)),
					"$and": [
						{"status.value": db.command.gte(1),}
					],
					"shop_id.area_all.value":db.command.in( areaPower() ),
				},
				whereRecord: {},
				orderby: dbOrderBy,
				orderByFieldName: "",
				selectedIndexs: [],
				options: {
					pageSize,
					pageCurrent,
					filterData: {
						"provider_localdata": [{
								"text": "微信支付",
								"value": "wxpay"
							},
							{
								"text": "支付宝",
								"value": "alipay"
							},
							{
								"text": "苹果应用内支付",
								"value": "appleiap"
							}
						],
						"pay_status_localdata": [{
								"text": "未支付",
								"value": 0
							},
							{
								"text": "已支付",
								"value": 1
							},
							{
								"text": "已部分退款",
								"value": 2
							},
							{
								"text": "已全额退款",
								"value": 3
							}
						],
						"rate_localdata": [{
								"text": "好评",
								"value": 1
							},
							{
								"text": "中评",
								"value": 2
							},
							{
								"text": "差评",
								"value": 3
							}
						]
					},
				},
				imageStyles: {
					width: 64,
					height: 64
				},
			}
		},
		onLoad(e) {
			if (e._uid) {
				where_uid = db.command.elemMatch({
					_id: e._uid,
				})
				this.orderWhere = {
					"create_date.time_stamp": db.command.gt(this.startTime).and(db.command.lt(endTime)),
					"shop_id": where_uid,
				}
				this.$nextTick(() => {
					this.$refs.udb.loadData()
				})
			} else {
				where_uid = db.command.elemMatch({})
			}
			this.getRider()
			this.getArea()
		},
		onReady() {
			this.$refs.udb.loadData()
		},
		watch: {
			pushOrders() {
				this.$nextTick(() => { this.$refs.udb.loadData() })
			}
		},
		computed: {
			pushOrders() {
				return this.$store.state.orderPushMsg
			}
		},
		methods: {
			// demo click
			onclick() {
			},
			// 获取地址
			async getArea(){
				
				this.dataTree = getArea()
			},
			getRider() {
				let Field = "avatar,name as text,order_number,mobile,_id"
				db.collection("rider_users").limit(999).where({
					is_online: true,
					status: true,
					"examine_status.value": 1,
					"area_all.value":db.command.in( areaPower() ),
				}).field(Field).get({getOne: false,customUI: true}).then(res => {
					let Data = res.result.data
					let tempData = Data.map((item, index) => {
						item.value = index
						return item
					})
					this.rangeRider = tempData
				})
			},
			// Where 筛选
				// 所在地区选择
			onchange(e) {
				this.orderWhere["shop_id.area_all.value"] =  e.detail.value[0].value
				this.$nextTick(() => {
					this.$refs.udb.loadData();
				});
			},
			onFilter(event, filter) {
				event.filter = event.filter.length === 0 ? [''] : event.filter
				let result = filterToWhere(event.filter, filter)
				// 将筛选结果保存到 whereRecord 对象中
				this.whereRecord[filter] = result;
				this.onRecord(filter)
			},
			onRecord( filter) {
				// 获取 whereRecord 对象的所有键
				const objKeys = Object.keys(this.whereRecord);
				// 创建 where 数组，用于构建查询条件
				const where = objKeys.map(item => {
					return {
						"$or": [...this.whereRecord[item]],
						"shop_id.area_all.value":db.command.in( areaPower() ),
					};
				});
				// 根据不同的筛选条件设置订单查询条件
				// 如果不是更改订单状态，则设置为有效订单状态
				// 如果是更改订单状态，则只保留 create_date.time_stamp 条件
				this.orderWhere = filter !== 'status' ? {
						"create_date.time_stamp": this.orderWhere["create_date.time_stamp"],"status.value": db.command.gte(1)
					} :
					{
						"create_date.time_stamp": this.orderWhere["create_date.time_stamp"]
					};

				// 将 where 条件添加到 orderWhere 的 $and 属性中
				this.orderWhere.$and = where;
				// 使用 $nextTick 确保更新后再加载数据
				this.$nextTick(() => {
					this.$refs.udb.loadData();
				});
			},

			/**
			 * 商家催单
			 * @param type -0.催接单、1催出餐  */
			eventVoice(type) {
				uni.showLoading({title: '正在呼出···'})
				let http = 'https://api.yipaidaojia.com/index.php/api/aliyun_voice'
				let data = {tel: this.temp_uid,token: '86f24d4bf67694706a347dc36f3365c0'}
				uni.request({method: 'POST',url: http,data: data}).then(res => {
					uni.hideLoading()
					this.$refs.showStatus.close()
					uni.showToast({title: '呼出成功'})
				})
			},
			/**
				取消订单-退款
			*/
			async toRefund() {
				let that = this;
				const orderNo = this.temp_uid.order_no
				uni.showModal({title: '提示',content: '确定要取消订单吗？',}).then(async res => {
					if ( !res.confirm ) return
					const db = uniCloud.database()
					this.$refs.showOrderOut.close()
					uni.showLoading({title:'退款中',mask:true})
					let refund = uniCloud.importObject("j-orders-refund", {customUI: true})
					refund.setOrdersRefund(orderNo,'后台取消',false).then(res=>{
						uni.hideLoading()
						this.$nextTick(() => {
							this.$refs.udb.loadData()
						})
						if(res.code === 200)return uni.showToast({title:res.error,icon:"none"})
						else return uni.showToast({title:res.error,icon:"none"})
					})
					const ordersStatus = await global.getDataOne("orders", {order_no: orderNo}, "status,address,rider,provider")
					const out_trade_no = await db.collection('uni-pay-orders').where({order_no: orderNo,status: 1 }).field('_id,order_no,out_trade_no').get({getOne: true,customUI: true})
					if(out_trade_no.result.affectedDocs > 0 &&ordersStatus.data.provider.value != 'yue'){
						this.$refs.pay.refund({
							out_trade_no: out_trade_no.result.data.out_trade_no, // 插件支付单号
							refund_desc: '订单号' + orderNo + '退款金额已到账'
						})
					}
				})
				
			},
			/*** 只退回金额*/
			async moneyRefund() {
				let that = this
				const orderNo = this.temp_uid.order_no
				const ordersStatus = await global.getDataOne("orders", {order_no: orderNo}, "status,address,rider")
				const out_trade_no = await db.collection('uni-pay-orders').where({order_no: orderNo,status: 1 }).field('_id,order_no,out_trade_no').get({getOne: true,customUI: true})
				this.$refs.showOrderOut.close()
				this.$refs.pay.refund({
					out_trade_no: out_trade_no.result.data.out_trade_no, // 插件支付单号
					refund_desc: '订单号' + orderNo + '退款金额已到账'
				}).then(orderRefundResult => {
					uni.showToast({title: '金额已退回' })
				}).catch(error => {
					global.addDataToUserLog({type: 2,text: `订单号：${that.orderNo},后台退款失败,失败原因：` + error});
					uni.showModal({title: "金额退回失败",content: '失败原因：' + error})
				})
			},
			// 状态更换
			updateStatus() {
				let orderNo = this.temp_uid.order_no
				let status = this.rangeStatus[this.selectStatus === 9 ? 6 : this.selectStatus]
				let payDate = this.temp_uid.pay_date
				let createDate = this.temp_uid.create_date.time_stamp
				updateStatus(orderNo, status, payDate, createDate).then(result => {
					this.$refs.showUpdateStatus.close()
					if (result.code === 200)
						return uni.showToast({
							title: "状态修改成功"
						}).then(() => {
							this.$nextTick(() => {
								this.$refs.udb.loadData()
							})
						})
				})
			},
			// 骑手选择
			handleItemClick(item, index) {
				this.selectRider = index
				let tempRider = this.rangeRider[this.selectRider]
			},
			// 更换骑手
			updateRider() {
				this.$refs.showUpdateRider.close()
				let orderNo = this.temp_uid.order_no
				let tempRider = this.rangeRider[this.selectRider]
				let money = this.temp_uid.delivery_price
				let currentRiderId = this.temp_uid.rider ? this.temp_uid.rider.user_id : null
				updateRider(orderNo, tempRider, money, currentRiderId).then(result => {
					if (result.code === 200)
						return uni.showToast({title: "更换成功"}).then(() => {
							this.getRider()
							this.$nextTick(() => { this.$refs.udb.loadData() })
						})
					else
						return uni.showModal({title: "更换失败",  content: result.error })
				})
			},
			
			onOpention(item, index) {
				if (index === 1) {
					this.temp_uid = item[0].tel
					this.$refs.showStatus.open()
				} else if (index === 2) {
					// 退款
					this.temp_uid = item
					this.$refs.showOrderOut.open()
				} else if (index === 3) {
					this.temp_uid = item
					this.$refs.showUpdateRider.open()
				} else if (index === 4) {
					this.temp_uid = item
					this.selectStatus = item.status.value
					this.$refs.showUpdateStatus.open()
				}
			},
			onqueryload(data) {
				// console.log(data);
				this.exportExcelData = data
			},
			isPower(admin = ['']) {
				return Util.userHasPermission(admin)
			},
			// 搜索
			search() {
				const nameVal = this.query
				// 合并查询条件
				let MergeWhere = {};
				// 构建搜索条件
				let search = {
					"shop_id.area_all.value":db.command.in( areaPower() ),
					$or: [
						/*- 搜索可根据名称进行模糊匹配*/
						{  'order_no': {  $regex: '.*' + nameVal + '.*', $options: 'i' } },
						{ 'address.phone': { $regex: '.*' + nameVal + '.*',$options: 'i' }  }
					]
				};
				this.orderWhere = Object.assign(MergeWhere, search)
				this.$nextTick(() => {
					this.$refs.udb.loadData()
				})
			},
			loadData(clear = true) {
				this.$refs.udb.loadData({
					clear
				})
			},
			onPageChanged(e) {
				this.selectedIndexs.length = 0
				this.$refs.table.clearSelection()
				this.$refs.udb.loadData({
					current: e.current
				})
			},
			navigateTo(url, clear) {
				// clear 表示刷新列表时是否清除页码，true 表示刷新并回到列表第 1 页，默认为 true
				uni.navigateTo({
					url,
					events: {
						refreshData: () => {
							this.loadData(clear)
						}
					}
				})
			},
			IsAdddress(address) {
				if (address)
					if (typeof address.name === 'undefined') return false
				else return true
				else return false
			},
			mobileReconfiguration(mobile) {
				return Util.formatPhoneNumber(mobile)
			},
			// 日期更换
			datetimePicker(e){
				if(e.length > 0){
					this.startTime = e[0]
					this.endTime = e[1]
				}else{
					this.startTime = Util.getDayTimestamps(0).startTime
					this.endTime = Util.getDayTimestamps(0).endTime
				}
				this.updateDateWhere()
			},
			// 下拉框
			changeDateSelect(e) {
				if (e == 0) {
					this.startTime = Util.getDayTimestamps(e).startTime
					this.endTime = Util.getDayTimestamps(e).endTime
				} else if (e == 1) {
					this.startTime = Util.getStartAndEndTimestamp(1).startTime
					this.endTime = Util.getStartAndEndTimestamp(0).startTime
				} else if (e == 2) {
					this.startTime = Util.getStartAndEndTimestamp(6).startTime
					this.endTime = Util.getStartAndEndTimestamp(6).endTime
				} else if (e == 3) {
					this.startTime = Util.getStartAndEndTimestamp(30).startTime
					this.endTime = Util.getStartAndEndTimestamp(30).endTime
				}
				this.selectTimeVal = e
				this.updateDateWhere()
			},
			updateDateWhere(){
				if (where_uid) {
					this.orderWhere = {
						"create_date.time_stamp": db.command.gt(this.startTime).and(db.command.lt(this.endTime)),
						"shop_id": where_uid,
						"status.value": this.orderWhere["status.value"],
						"$and": this.orderWhere.$and,
						"shop_id.area_all.value":this.orderWhere["shop_id.area_all.value"],
					}
				} else {
					this.orderWhere = {
						"create_date.time_stamp": db.command.gt(this.startTime).and(db.command.lt(this.endTime)),
						"status.value": this.orderWhere["status.value"],
						"$and": this.orderWhere.$and,
						"shop_id.area_all.value":this.orderWhere["shop_id.area_all.value"],
					}
				}
				this.$nextTick(() => {
					this.$refs.udb.loadData()
				})
			},
			// 复制订单号
			copyOrderNo(orderNo){
				uni.setClipboardData({
					data:orderNo,
					showToast:false,
					success: function () {
						uni.showToast({title:"复制成功",icon:"none"})
					}
				})
			},
			// 给数字字符串添加空格
			formatBankCardNumber(string) {
				return Util.formatBankCardNumber(string)
			},
			onStatus(Num) {
				return Util.onStatus(Num)
			},
			// 多选处理
			selectedItems() {
				var dataList = this.$refs.udb.dataList
				return this.selectedIndexs.map(i => dataList[i]._id)
			},
			// 批量删除
			delTable() {
				this.$refs.udb.remove(this.selectedItems(), {
					success: (res) => {
						this.$refs.table.clearSelection()
					}
				})
			},
			// 多选
			selectionChange(e) {
				this.selectedIndexs = e.detail.index
			},
			sortChange(e, name) {
				this.orderByFieldName = name;
				if (e.order) {
					this.orderby = name + ' ' + orderByMapping[e.order]
				} else {
					this.orderby = ''
				}
				this.$refs.table.clearSelection()
				this.$nextTick(() => {
					this.$refs.udb.loadData()
				})
			},
		}
	}
</script>
<style scoped lang="scss">
	.copy{
		font-size:12px;
		color:#777;
	}
	.container{
		width:150rpx;
		  overflow: hidden; /* 超出部分隐藏 */
		  text-overflow: ellipsis; /* 使用省略号代替被截断的文本*/
		  display: -webkit-box; /* 将元素作为弹性伸缩盒子 */
		  -webkit-line-clamp:1; /* 最多显示两行 */
		  -webkit-box-orient: vertical; /* 设置弹性伸缩盒子的子元素垂直排列 */
	}
	.container{
		width:150rpx;
		  overflow: hidden;
		  white-space: nowrap;
		  text-overflow: ellipsis;
	}
	.maxbox {
		max-height: 500px;
		overflow: auto;
	}

	.grid {
		padding: 0rpx 0 0 0;
		display: grid;
		grid-template-columns: repeat(auto-fill, minmax(150rpx, 1fr));

		.item_box:hover {
			background-color: #f4f6ff;
			transition: .5s;
		}

		.image {
			width: 40px;
		}

		.item_box {
			transition: .5s;
			cursor: pointer;
			margin: 8px;
			text-align: center;
			padding: 5px 0 0 0;
			border: 1px solid #eee;
			border-radius: 10px;

			.title {
				font-weight: bold;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
			}

			.label {
				font-size: 14px;
				color: #999;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 1;
				-webkit-box-orient: vertical;
			}
		}

		.item_boxTow {
			background-color: #f4f6ff;
			border: 1px solid #36d;
		}
	}

	.select {
		width: 250rpx;
		margin: 0 20rpx;
	}

	.title {
		font-weight: bold;
		line-height: 70rpx;
	}

	.popup {
		border-radius: 10rpx;

		.body {
			padding: 0 0 0 20rpx;
		}

		width:500px;
		min-height:200px;
		padding:30rpx;

		button {
			margin: 0 50rpx;
		}
	}
</style>